<?php

  require_once __CFG_PATH_LIBS_ADMIN."xx/class.Statistic.php";

  /*$FilterParamArray = array('seo_part');
  saveFilterParams($FilterParamArray);*/

  $stat = new Statistic();

  $StatDates = $stat->getStatisticDates($_SQL_TABLE[$GlobPart]);

  /*$StatSeoParts = array();
  foreach($StatDates as $date => $val)
  {    $StatSeoParts[$date] = $stat->getStatisticSeoParts($_SQL_TABLE[$GlobPart].$CONFIG['AdminDBTableNameDelim'].$date);
  } */
  reset($StatDates);
  krsort($StatDates);
  reset($StatDates);
  if(isBlank($_GET['tdate']))
  {
    $_GET['tdate'] = key($StatDates);
  }
  /*if(isBlank($_GET['seo_part']))
  {
    $_GET['seo_part'] = key($StatSeoParts[$_GET['tdate']]);
  } */

  $tabNameParts[] = $_SQL_TABLE[$GlobPart];
  $tabNameParts[] = $_GET['tdate'];
  //$tabNameParts[] = $_GET['seo_part'];

  if(!$stat->checkTableExists($tabNameParts, 'createRefererTable', __FALSE))
  {  	$_FLAGS['NoReadDB'] = __TRUE;
    $BodyTemplate = 'admin.body_megaerror.tpl';
    $MegaError['title'] = $ERRORS['admin'][__ERROR_NO_DATA_FOR_THIS_PERIOD];
  }
  $WorkTable = $stat->getFullTableName($tabNameParts);

  if(!isBlank($_GET['tdate']) && !isBlank($_GET['seo_part']))
  {
    $_FLAGS['DateSelected'] = __TRUE;
  }

  if($_REQUEST['mode'] == $GlobPart)
  {
    $PageTitle = '$language["admin"]["referers"]." :: ".$Item["id"];';
  }
  else
  {
  	$PageTitle = '$language["admin"]["referers"];';
  	$AloneMode = $GlobPart;

  	$Query['FromTables'] = 	$WorkTable." r
  							";
  	$Query['Fields'] = "r.*";
  	$Query['TabOrder'] = "r.";
  	$Query['Where'] = "";
  	$Query['GroupBy'] = "";

  	if(isBlank($_GET['order']))
  	{  	  $listInfo['order'] = 'date';
  	  $listInfo['order_type'] = 'DESC';
  	}

  	$EnableFilter = true;

  	$FilterButtons['filter_reset'] = array(
					'value' => $language['admin']['resetFilterButton'],
					'onclick' => "document.getElementById('filter_tdate').disabled='';document.getElementById('filter_seo_part').disabled='';document.getElementById('filter_client_domain').disabled='disabled';document.getElementById('filter_ip').disabled='disabled';document.getElementById('filter_country').disabled='disabled';",
					'other' => 'class="redbutton"',
    );
  }

  $listInfo['where']['tdate'] = array(
  								'simple' => 'y',
  								'type' => 'select',
  								'title' => $language['admin']['date'],
  								'values' => $StatDates,
  								'other' => (($_FLAGS['DateSelected'] == __TRUE) ? 'disabled' : '').' onchange="setfilter_seo_part(this.value);"',
  								);

  /*$listInfo['where']['seo_part'] = array(
  								'simple' => 'y',
  								'type' => 'JSselect',
  								'title' => $language['admin']['seoPart'],
  								'values' => $StatSeoParts,
  								'parentID' => 'filter_tdate',
  								'other' => (($_FLAGS['DateSelected'] == __TRUE) ? 'disabled ' : ''),
  								);*/

  if($_FLAGS['DateSelected'] == __TRUE)
  {
    $ClientDomainsSelect = array_kv(getTableAsArray($_SQL_TABLE['client_domain'], 'sitedomain', array(), '', 'id,sitedomain'), 'sitedomain', 'id');
    $TabFields['cc'] = getFieldNamesWithLangs($_SQL_TABLE['country'], array('title'));
    $CountriesSelect = array_kv(getTableAsArray($_SQL_TABLE['country'], $TabFields['cc']['title'], array(), '', 'code,'.$TabFields['cc']['title']), $TabFields['cc']['title'], 'code');

    $listInfo['where']['referer'] = array(
  								'simple' => 'y',
  								'type' => 'checkbox',
  								'checkedValue' => 'y',
								'checked' => $_GET['referer'],
  								'SQLField' => ((!isBlank($_REQUEST['referer'])) ? "r.referer != ''" : "" ),
  								'title' => $language['admin']['referer'],
  								'textAfterField' => $language['admin']['yes'],
  								'JSact' => '(document.getElementById("filter_referer").checked!="") ? document.getElementById("filter_referer").value : ""',
  								'newRow' => 'y',
  								);

    $listInfo['where']['client_domain'] = array(
  								'simple' => 'y',
  								'type' => 'select',
  								'SQLField' => "r.client_domain = '".$_REQUEST['client_domain']."'",
  								'title' => $language['admin']['clientDomain'],
  								'values' => array('' => $language['admin']['all']) + $ClientDomainsSelect,
  								'JSact' => '(document.getElementById("filter_client_domain").disabled=="") ? document.getElementById("filter_client_domain").value : ""',
  								'newRow' => 'y',
  								);

  	$listInfo['where']['ip'] = array(
  								'simple' => 'y',
  								'type' => 'input',
  								'SQLField' => "r.ip LIKE '".$_REQUEST['ip']."%'",
  								'title' => $language['admin']['ip'],
  								'JSact' => '(document.getElementById("filter_ip").disabled=="") ? document.getElementById("filter_ip").value : ""',

  								);

  	$listInfo['where']['country'] = array(
  								'simple' => 'y',
  								'type' => 'select',
  								'SQLField' => "r.country = '".$_REQUEST['country']."'",
  								'title' => $language['admin']['country'],
  								'values' => array('' => $language['admin']['all']) + $CountriesSelect,
  								'JSact' => '(document.getElementById("filter_country").disabled=="") ? document.getElementById("filter_country").value : ""',
  								'newRow' => 'y',
  								);


  }

  require_once __CFG_PATH_CODE_ADMIN."admin.filter.inc";


  $_SQL_TABLE_FIELDS[$GlobPart] = array(

				'client_domain' => array(
								'type' => 'select',
								'title' => $language['admin']['clientDomain'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['client_domain'],
								'useInList' => $CONFIG['useInListSort'],
								'orderby' => 'sitedomain,r.date-DESC',
								'tabord' => 'cd.',
								'values' => $ClientDomainsSelect,
								),

				'link' => array(
								'type' => 'value',
								'title' => $language['admin']['link'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['link'],
								'useInList' => $CONFIG['useInListSort'],
								'inListSmartyMods' => array('truncate:40:"...":true'),
								'inListWzTooltip' => 'y',
								),

				'ip' => array(
								'type' => 'value',
								'title' => $language['admin']['ip'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['ip'],
								'useInList' => $CONFIG['useInListSort'],
								),

				'country' => array(
								'type' => 'select',
								'title' => $language['admin']['country'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['country'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $CountriesSelect,
								),

                'camp' => array(
								'type' => 'value',
								'title' => $language['admin']['campaign'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['camp'],
								'useInList' => $CONFIG['useInListSort'],
								),

				'subcamp' => array(
								'type' => 'value',
								'title' => $language['admin']['subCampaign'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['subcamp'],
								'useInList' => $CONFIG['useInListSort'],
								),

				'keyword' => array(
								'type' => 'value',
								'title' => $language['admin']['keyword'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['keyword'],
								'useInList' => $CONFIG['useInListSort'],
								),

				'date' => array(
								'type' => 'value',
								'title' => $language['admin']['date'],
								'addVariable' => 'NOW()',
								'addVarType' => $CONFIG['VarTypeSQLFunction'],
								'useInList' => $CONFIG['useInListSort'],
								'useInListEdit' => 'y',
								),

				'referer' => array(
								'type' => 'value',
								'title' => $language['admin']['referer'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['referer'],
								'useInList' => $CONFIG['useInListShow'],
								'inListNewRow' => 'y',
								'isLink' => 'y',
								'linkTarget' => '_blank',
								'inListSmartyMods' => array('truncate:140:"...":true'),
								'inListWzTooltip' => 'y',
								),

  );

  $_SQL_TABLE_EDIT_FORMS[$GlobPart] = array('active');

  $NoUse['SaveButton'] = 'y';
  $NoUse['SaveItemButton'] = 'y';
  $NoUse['DeleteButton'] = 'y';
  $NoUse['ActivateButton'] = 'y';
  $NoUse['DeactivateButton'] = 'y';
  $NoUse['AddButton'] = 'y';


?>